const mongoose = require("mongoose")
let shopsModel = mongoose.model("shopsModel")

// 获取门店
// module.exports.getShops = async function (shops){
//     const total = await shopsModel.countDocuments();
//     const rows = await shopsModel.find(shops).populate("storesId")
//     console.log(total,rows)
//     return {total,rows}
// }

// 分面渲染
module.exports.getShopsByPage = async function ({pageSize,nowPage,state}){
    const total = (await shopsModel.find({state})).length;
    console.log(33333333333,state)
    const rows = await shopsModel
    .find({state})
    .populate("storesId")
    .limit(pageSize - 0)   // limit(number) 用于设置请求数据的条数
    .skip((nowPage - 1) * pageSize);
    console.log('3333333333数据',rows)
    console.log('3333333333总条数',total)
    return {total,rows}
}



// 获取门店
module.exports.updateShops  = async function ({_id,name,address,state,shopsId}){
    // console.log(333333333333333,{_id,name,address,state,shopsId})
    return await shopsModel.updateOne({_id},{name,address,state,shopsId})
}


module.exports.addShops = async function(shop){
    return await shopsModel.create(shop)
}